﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Web.Security;
using Bansud.SGR.CommonSGR;
namespace condortravel.operaciones.common
{
    public class SecurityEncrypt
    {
        
	// Private plainText As String
	//Private cipherText As String

	private string passPhrase;
	private string saltValue;
	private string hashAlgorithm;
	private int passwordIterations;
	private string initVector;

	private int keySize;

    public SecurityEncrypt()
	{
		passPhrase = "Pas5pr@se";
		// can be any string
		saltValue = "s@1tValue";
		// can be any string
		hashAlgorithm = "SHA1";
		// can be "MD5"
		passwordIterations = 2;
		// can be any number
		initVector = "@1B2c3D4e5F6g7H8";
		// must be 16 bytes
		keySize = 256;
		// can be 192 or 128
	}

	public string Encrypt(string plainText)
	{
		//  Dim _SGRSecurity As New SGRSeguridad
		string cipherText = string.Empty;

		if ((plainText != null)) {
            cipherText = SGRSeguridad.Encrypt(plainText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
		}

		return cipherText;

	}

	public string Decrypt(string cipherText)
	{
		//  Dim _SGRSecurity As New SGRSeguridad
		string plainText = string.Empty;

		if ((cipherText != null)) {
            plainText = SGRSeguridad.Decrypt(cipherText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
		}

		return plainText;

	}

	public static string Encrypt2(string plainText)
	{
		//  Dim _SGRSecurity As New SGRSeguridad
		string cipherText = FormsAuthentication.HashPasswordForStoringInConfigFile(plainText, "Sha1");
		//cipherText = SGRSeguridad.Encrypt(plainText, _
		//                                passPhrase, _
		//                                saltValue, _
		//                                hashAlgorithm, _
		//                                passwordIterations, _
		//                                initVector, _
		//                                keySize)

		return cipherText;

	}


    }
}
